package servlet.man;

import bean.Manager;
import bean.Result;
import bean.Teacher;
import com.fasterxml.jackson.databind.ObjectMapper;
import dao.UserDaoImpl;
import service.UserService;
import service.UserServiceImpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * @author 李夏
 * @version 1.0
 */

//管理员注册
@WebServlet("/man/sign")
public class ManSignServlet extends HttpServlet {
    @Override
    protected void service(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        System.out.println("===============管理员注册页面=============");

        String manName = request.getParameter("manName");
        String manPassword = request.getParameter("password");
        int manId = Integer.parseInt(request.getParameter("manId"));
        int phone = Integer.parseInt(request.getParameter("phone"));



        UserService userService = new UserServiceImpl();
        Manager manager=null;
        try {
            manager = userService.manIsSignSuccess(manPassword, manId, manName, phone);
        }catch (Exception e) {
            Result result= new Result();
            result.fail(e.toString());
            ObjectMapper objectMapper = new ObjectMapper();
            String str = objectMapper.writeValueAsString(result);
            response.setContentType("application/json;charset=utf8");
            response.getWriter().print(str);
        }
        Result result = new Result();
        ObjectMapper objectMapper = new ObjectMapper();
        manager = new UserDaoImpl().manFindByPasswordAndId(manPassword,manId);

        result.success(manager);
        String str = objectMapper.writeValueAsString(result);
        response.setContentType("application/json;charset=utf8");
        response.getWriter().print(str);







    }
}
